<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<link rel="stylesheet" href="${ctx}/webjars/layui/2.3.0/css/layui.css">
<script src="${ctx}/webjars/jquery/3.3.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="${ctx}/webjars/layui/2.3.0/layui.all.js"
        charset="utf-8"></script>
<title>查询患者信息</title>
<script src="${ctx}/webjars/layui/2.3.0/layui.all.js" type="text/javascript"></script>
<script src="${ctx}/webjars/layui/2.3.0/lay/modules/laypage.js" type="text/javascript"></script>
</head>
<body>
<!--右侧具体内容 开始-->
<div class="main">
    <div class="right_jtnr"><h1>查询患者信息</h1></div>
    <div class="right_filter demoTable">
        <div class="filter_left">
            <div class="filter_wz">医院：</div>
            <div class="filter_select" style="width: 180px;">
                <input name="yljgdm" id="yljgdm" autocomplete="off">
            </div>
            <div class="filter_wz">科室名称：</div>
            <div class="filter_mc">
                <input name="patno" id="patno" autocomplete="off">
            </div>
        </div>
        <div class="filter_right">
            <button class="layui-btn filter_cx" data-type="reload">查询</button>
        </div>
    </div>

    <!--右侧具体内容 结束-->
    <!--右侧管理表格 开始-->
    <script type="text/html" id="barDemo">
        <a class="layui-btn filter_cx table-btn" lay-event="detail">查看</a>
        <a class="layui-btn filter_cx table-btn" lay-event="edit">编辑</a>
        <%--<a class="layui-btn filter_cx" lay-event="del">删除</a>--%>
    </script>
    <table class="right_table" lay-filter="test" style="width: 100%;height: 100%;">
    </table>
    <div id="laypage"></div>
    <%--</div>--%>
    <table class="layui-hide" id="test" lay-filter="demo"></table>

</div>
</body>
<script>
    var hospitalCode =document.getElementById("hospitalCode");
    var regDeptId = document.getElementById("regDeptId");
    layui.config({
        version: '1520760931738' //为了更新 js 缓存，可忽略
    });
    layui.use(['laydate', 'laypage', 'layer', 'table', 'element'], function () {
        var laydate = layui.laydate //日期
            , laypage = layui.laypage //分页
        layer = layui.layer //弹层
            , table = layui.table //表格
            , element = layui.element; //元素操作
        //监听Tab切换
        element.on('tab(demo)', function (data) {
            layer.msg('切换了：' + this.innerHTML);
            console.log(data);
        });
        //方法级渲染
        table.render({
            elem: '#test'
            , url: '${ctx}/query/getPersonInfo'
            , type: 'POST'
            , page: true //开启分页
            , cols: [[
                {field: 'hospitalCode', title: '机构代码', width: 120, sort: true}
                ,{field: 'fullName', title: '机构名称', width: 120, sort: true}
                , {field: 'address', title: '机构地址', width: 120, sort: true}
                , {field: 'levelText', title: '机构等级', width: 120, sort: true}
                , {field: 'regDeptId', title: '科室代码', width: 100, sort: true}
                , {field: 'regDeptName', title: '科室名称', width: 100, sort: true}
                , {field: 'standardCode', title: '标准科室代码', width: 100, sort: true}
                , {field: 'standardName', title: '标准科室名称', width: 100, sort: true}
                , {field: 'denyCardType', title: '卡类型限制', width: 100, sort: true}
                , {field: 'ageRange', title: '年龄限制', width: 100, sort: true}

                , {field: 'right', title: '操作', width: 230, toolbar: "#barDemo"}
            ]]
            , limit: 10
            , id: 'testReload'
            , initSort: {field: 'hospitalCode', type: 'asc'}
            , request: {
                pageName: 'pageNo' //页码的参数名称，默认：page
                , limitName: 'limit' //每页数据量的参数名，默认：limit
            }
            , response: {
                statusName: 'code' //数据状态的字段名称，默认：code
                , msgName: 'msg' //状态信息的字段名称，默认：msg
                , countName: 'count' //数据总数的字段名称，默认：count
                , dataName: 'data' //数据列表的字段名称，默认：data
            }
        });
        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                var json = JSON.stringify(data);
                var object = JSON.parse(json);
                window.location.href = "${ctx}/standardDept/deptDetail?hospitalCode=" + object.hospitalCode+"&deptCode="+object.regDeptId;
                window.target = "_self";
            } else if (obj.event === 'edit') {
                var json = JSON.stringify(data);
                var object = JSON.parse(json);
                window.location.href = "${ctx}/standardDept/toUpdateDept?hospitalCode=" + object.hospitalCode+"&deptCode="+object.regDeptId;
                window.target = "_self";
            }
        });

        laypage.render({
            elem: 'pageDemo' //分页容器的id
            , count: 'count' //总页数
            , skin: '#1E9FFF' //自定义选中色值
            //,skip: true //开启跳页
            , jump: function (obj, first) {
                if (!first) {
                    layer.msg('第' + obj.curr + '页');
                }
            }
        });

        var $ = layui.$, active = {
            reload: function () {
                var patno = $('#patno');
                var yljgdm=$('#yljgdm')
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        patno: patno.val(),
                        yljgdm: yljgdm.val()

                    }
                });
            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });

    function add() {
        window.location.href = '${ctx}/standardDept/toAddDept';
        window.location.target = '_self';
    }
</script>
</html>